package com.cocotingo.snail.template.models;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.cocotingo.snail.template.TemplateSyntaxException;

public class PaintNode extends Node {
	
	private List<PaintFactorNode> factors;
	
	public PaintNode() {
		factors = new ArrayList<PaintFactorNode>(1);
	}
	
	public final void addPaintFactor(PaintFactorNode factor) {
		this.addPaintFactor(factor, factors.size());
	}
	
	public void addPaintFactor(PaintFactorNode factor, int index) {
		if (factor == null) throw new IllegalArgumentException("cannot add null as a child node");
		factors.add(index, factor);
	}
	
	public void removePaintFactor(PaintFactorNode factor) {
		factors.remove(factor);
	}
	
	public Iterable<PaintFactorNode> factors() {
		return new Iterable<PaintFactorNode>() {
			@Override
			public Iterator<PaintFactorNode> iterator() {
				return factors.iterator();
			}
		};
	}

	@Override
	public void validateNode() throws TemplateSyntaxException {
	}
	
	@Override
	public Iterable<Node> children() {
		return new Iterable<Node>() {
			@Override
			public Iterator<Node> iterator() {
				return new Iterator<Node>() {
					Iterator<PaintFactorNode> it = factors.iterator();
					@Override
					public boolean hasNext() {
						return it.hasNext();
					}
					@Override
					public Node next() {
						return it.next();
					}
					@Override
					public void remove() {
						throw new UnsupportedOperationException();
					}
				};
			}
		};
	}

	@Override
	protected String getXMLNodeName() {
		return "Paint";
	}

	@Override
	protected String getXMLAttributes() {
		return null;
	}
	
}
